package com.example.dingding.util;

import com.aliyun.dingtalkworkflow_1_0.models.*;
import com.aliyun.tea.TeaException;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.Common;
import com.aliyun.teautil.models.RuntimeOptions;
import lombok.extern.slf4j.Slf4j;

//创建审批表单
@Slf4j
public class Sample3 {
    public static String getAccessToken() throws Exception {
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
        config.protocol = "https";
        config.regionId = "central";
        com.aliyun.dingtalkoauth2_1_0.Client client = new com.aliyun.dingtalkoauth2_1_0.Client(config);
        com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenRequest getAccessTokenRequest
                = new com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenRequest()
                .setAppKey("dingzvtl6gimsru7ymlx")
                .setAppSecret("Fj4xtc4l5cScmZhfNCkAcCMPFRA5XKq26BxDYOWCMQrra6iCSbmGuKIYkPrx9t9o");
        try {
            return client.getAccessToken(getAccessTokenRequest).getBody().getAccessToken();
        } catch (TeaException err) {
            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
                // err 中含有 code 和 message 属性，可帮助开发定位问题
            }

        } catch (Exception _err) {
            TeaException err = new TeaException(_err.getMessage(), _err);
            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
                // err 中含有 code 和 message 属性，可帮助开发定位问题
            }

        }
        return null;
    }

    public static void main(String[] args) throws Exception {
        Config config = new Config();
        config.protocol = "https";
        config.regionId = "central";
        com.aliyun.dingtalkworkflow_1_0.Client client = new com.aliyun.dingtalkworkflow_1_0.Client(config);
        FormCreateHeaders formCreateHeaders = new FormCreateHeaders();
        formCreateHeaders.xAcsDingtalkAccessToken = getAccessToken();

        //多选框选择紧急程度
        SelectOption option1=new SelectOption();
        option1.setKey("option1");
        option1.setValue("较小");
        SelectOption option2=new SelectOption();
        option2.setKey("option2");
        option2.setValue("一般");
        SelectOption option3=new SelectOption();
        option3.setKey("option3");
        option3.setValue("较大");
        SelectOption option4=new SelectOption();
        option4.setKey("option4");
        option4.setValue("严重");
        SelectOption option5=new SelectOption();
        option5.setKey("option5");
        option5.setValue("紧急");
        FormComponentProps formComponentProps1 = new FormComponentProps()
                .setComponentId("TextField-title")
                .setPlaceholder("紧急程度")
                .setLabel("紧急程度")
                .setOptions(java.util.Arrays.asList(option1,option2,option3, option4,option5))
                .setRequired(false);
        FormComponent formComponent1 = new FormComponent()
                .setComponentType("DDMultiSelectField")
                .setProps(formComponentProps1);

        FormComponentProps formComponentProps2 = new FormComponentProps()
                .setComponentId("TextField-title2")
                .setPlaceholder("请输入")
                .setLabel("乘车人员")
                .setRequired(false);
        FormComponent formComponent2 = new FormComponent()
                .setComponentType("TextField")
                .setProps(formComponentProps2);


        FormComponentProps formComponentProps3 = new FormComponentProps()
                .setComponentId("TextField-title3")
                .setPlaceholder("联系电话")
                .setLabel("联系电话")
                .setRequired(false);
        FormComponent formComponent3 = new FormComponent()
                .setComponentType("TextField")
                .setProps(formComponentProps3);


        SelectOption op1=new SelectOption();
        op1.setKey("option1");
        op1.setValue("机要通信用车");
        SelectOption op2=new SelectOption();
        op2.setKey("option2");
        op2.setValue("会议用车");
        SelectOption op3=new SelectOption();
        op3.setKey("option3");
        op3.setValue("应急用车");
        SelectOption op4=new SelectOption();
        op4.setKey("option4");
        op4.setValue("检查调研用车");
        SelectOption op5=new SelectOption();
        op5.setKey("option5");
        op5.setValue("公务接待车");
        SelectOption op6=new SelectOption();
        op6.setKey("option6");
        op6.setValue("老干用会慰问用车");
        SelectOption op7=new SelectOption();
        op7.setKey("option");
        op7.setValue("其他用车");
        FormComponentProps formComponentProps4 = new FormComponentProps()
                .setComponentId("TextField-title4")
                .setPlaceholder("用车事由")
                .setLabel("用车事由")
                .setOptions(java.util.Arrays.asList(op1,op2,op3,op4,op5,op6,op7))
                .setRequired(false);
        FormComponent formComponent4 = new FormComponent()
                .setComponentType("DDMultiSelectField")
                .setProps(formComponentProps4);

        SelectOption opt1=new SelectOption();
        opt1.setKey("opt1");
        opt1.setValue("长沙区域");
        SelectOption opt2=new SelectOption();
        opt2.setKey("opt2");
        opt2.setValue("省内区域");
        SelectOption opt3=new SelectOption();
        opt3.setKey("opt3");
        opt3.setValue("省外区域");
        FormComponentProps formComponentProps5 = new FormComponentProps()
                .setComponentId("TextField-title5")
                .setPlaceholder("点击选择目的地区域")
                .setLabel("目的地区域")
                .setOptions(java.util.Arrays.asList(opt1,opt2,opt3))
                .setRequired(false);
        FormComponent formComponent5 = new FormComponent()
                .setComponentType("DDMultiSelectField")
                .setProps(formComponentProps5);

        FormComponentProps formComponentProps6 = new FormComponentProps()
                .setComponentId("TextareaField-6")
                .setPlaceholder("其他用车")
                .setLabel("其他用车")
                .setRequired(false);
        FormComponent formComponent6 = new FormComponent()
                .setComponentType("TextareaField")
                .setProps(formComponentProps6);

        FormComponentProps formComponentProps7 = new FormComponentProps()
                .setComponentId("TextField-title7")
                .setPlaceholder("请输入具体目的地")
                .setLabel("具体目的地")
                .setRequired(false);
        FormComponent formComponent7 = new FormComponent()
                .setComponentType("TextField")
                .setProps(formComponentProps7);



        SelectOption options=new SelectOption();
        options.setKey("options");
        options.setValue("工作日");
        SelectOption optiont=new SelectOption();
        optiont.setKey("optiont");
        optiont.setValue("周末");
        SelectOption optionb=new SelectOption();
        optionb.setKey("optionb");
        optionb.setValue("法定节假日");
        FormComponentProps formComponentProps8 = new FormComponentProps()
                .setComponentId("TextField-title8")
                .setPlaceholder("日期类型")
                .setLabel("日期类型")
                .setOptions(java.util.Arrays.asList(options,optiont,optionb))
                .setRequired(false);
        FormComponent formComponent8 = new FormComponent()
                .setComponentType("DDMultiSelectField")
                .setProps(formComponentProps8);


        SelectOption optionst=new SelectOption();
        optionst.setKey("optionyw1");
        optionst.setValue("一般业务用车");
        SelectOption optiontb=new SelectOption();
        optiontb.setKey("optionyw2");
        optiontb.setValue("业务用车");
        FormComponentProps formComponentProps9 = new FormComponentProps()
                .setComponentId("TextField-title9")
                .setPlaceholder("用车类别")
                .setLabel("用车类别")
                .setOptions(java.util.Arrays.asList( optionst,optiontb))
                .setRequired(false);
        FormComponent formComponent9 = new FormComponent()
                .setComponentType("DDMultiSelectField")
                .setProps(formComponentProps9);

        FormComponentProps formComponentProps10 = new FormComponentProps()
                .setComponentId("DDDateRangeField-10")
                .setPlaceholder("用车时间")
                .setLabel("用车时间")
                .setRequired(false);
        FormComponent formComponent10 = new FormComponent()
                .setComponentType("TextField")
                .setProps(formComponentProps10);



        FormComponentProps formComponentProps11 = new FormComponentProps()
                .setComponentId("DDDateRangeField-11")
                .setPlaceholder("返回时间")
                .setLabel("返回时间")
                .setRequired(false);
        FormComponent formComponent11 = new FormComponent()
                .setComponentType("TextField")
                .setProps(formComponentProps11);


        SelectOption optio1=new SelectOption();
        optio1.setKey("optio1");
        optio1.setValue("业务部");
        SelectOption optio2=new SelectOption();
        optio2.setKey("optio2");
        optio2.setValue("开发部");
        SelectOption optio3=new SelectOption();
        optio3.setKey("optio3");
        optio3.setValue("财务部");
        FormComponentProps formComponentProps12 = new FormComponentProps()
                .setComponentId("TextField-title11")
                .setPlaceholder("点击所在部门")
                .setLabel("所在部门")
                .setOptions(java.util.Arrays.asList(optio1,optio2,optio3))
                .setRequired(false);
        FormComponent formComponent12 = new FormComponent()
                .setComponentType("DDMultiSelectField")
                .setProps(formComponentProps12);

        FormComponentProps formComponentProps13 = new FormComponentProps()
                .setComponentId("TextField-title13")
                .setPlaceholder("出发地点")
                .setLabel("出发地点")
                .setRequired(false);
        FormComponent formComponent13 = new FormComponent()
                .setComponentType("TextField")
                .setProps(formComponentProps13);


//        SelectOption optionssq=new SelectOption();
//        optionssq.setKey("optionssq");
//        optionssq.setValue("否");
//        SelectOption optiontbtq=new SelectOption();
//        optiontbtq.setKey("optiontbtq");
//        optiontbtq.setValue("是");
//        FormComponentProps formComponentProps14 = new FormComponentProps()
//                .setComponentId("TextField-title14")
//                .setPlaceholder("是否缴纳用车费用")
//                .setLabel("是否缴纳用车费用")
//                .setOptions(java.util.Arrays.asList(optionssq,optiontbtq))
//                .setRequired(false);
//        FormComponent formComponent14 = new FormComponent()
//                .setComponentType("DDSelectField")
//                .setProps(formComponentProps14);

//        FormComponentProps formComponentProps14 = new FormComponentProps()
//                .setComponentId("TextField-title14")
//                .setPlaceholder("缴费金额")
//                .setLabel("缴费金额")
//                .setRequired(false);
//        FormComponent formComponent14 = new FormComponent()
//                .setComponentType("TextField")
//                .setProps(formComponentProps14);
        FormComponentProps formComponentProps14 = new FormComponentProps()
                .setComponentId("TextField-title14")
                .setPlaceholder("乘车人数")
                .setLabel("乘车人数")
                .setRequired(false);
        FormComponent formComponent14 = new FormComponent()
                .setComponentType("TextField")
                .setProps(formComponentProps14);

        FormComponentProps formComponentProps15 = new FormComponentProps()
                .setComponentId("TextField-title15")
                .setPlaceholder("司机电话")
                .setLabel("司机电话")
                .setRequired(false);
        FormComponent formComponent15 = new FormComponent()
                .setComponentType("TextField")
                .setProps(formComponentProps15);

        FormComponentProps formComponentProps16 = new FormComponentProps()
                .setComponentId("TextField-title16")
                .setPlaceholder("车牌号")
                .setLabel("车牌号")
                .setRequired(false);
        FormComponent formComponent16 = new FormComponent()
                .setComponentType("TextField")
                .setProps(formComponentProps16);

        FormComponentProps formComponentProps17 = new FormComponentProps()
                .setComponentId("TextField-title17")
                .setPlaceholder("司机姓名")
                .setLabel("司机姓名")
                .setRequired(false);
        FormComponent formComponent17 = new FormComponent()
                .setComponentType("TextField")
                .setProps(formComponentProps17);



        FormComponentProps formComponentProps18 = new FormComponentProps()
                .setComponentId("TextField-title18")
                .setPlaceholder("本次公里数")
                .setLabel("本次公里数")
                .setRequired(false);
        FormComponent formComponent18  = new FormComponent()
                .setComponentType("TextField")
                .setProps(formComponentProps18);

        FormComponentProps formComponentProps19 = new FormComponentProps()
                .setComponentId("TextField-title19")
                .setPlaceholder("原公里数")
                .setLabel("原公里数")
                .setRequired(false);
        FormComponent formComponent19 = new FormComponent()
                .setComponentType("TextField")
                .setProps(formComponentProps19);

        FormComponentProps formComponentProps20 = new FormComponentProps()
                .setComponentId("TextField-title20")
                .setPlaceholder("现公里数")
                .setLabel("现公里数")
                .setRequired(false);
        FormComponent formComponent20 = new FormComponent()
                .setComponentType("TextField")
                .setProps(formComponentProps20);

        //PROC-8C7EA2C8-E6B9-4389-A406-DE513011CCC8

        FormCreateRequest formCreateRequest = new FormCreateRequest()
                .setName("公务租车审批")
                .setDescription("公务租车审批")
                .setFormComponents(java.util.Arrays.asList(formComponent1, formComponent2,formComponent3,
                        formComponent4,formComponent5,formComponent6,formComponent7,
                        formComponent8,
                        formComponent9,
                        formComponent10,
                        formComponent11,
                        formComponent12,
                        formComponent13,
                        formComponent14,
                        formComponent15,
                        formComponent16,
                        formComponent17,
                        formComponent18,
                        formComponent19,
                        formComponent20
                ));
        try {
            FormCreateResponse formCreateResponse = client.formCreateWithOptions(formCreateRequest, formCreateHeaders,
                    new RuntimeOptions());
            System.out.println("创建的processCode：" + formCreateResponse.getBody().getResult().getProcessCode());
        } catch (TeaException err) {
            log.error("--->", err);
            if (!Common.empty(err.code) && !Common.empty(err.message)) {
                // err 中含有 code 和 message 属性，可帮助开发定位问题
            }

        } catch (Exception _err) {
            log.error("--->", _err);
            TeaException err = new TeaException(_err.getMessage(), _err);
            if (!Common.empty(err.code) && !Common.empty(err.message)) {
                // err 中含有 code 和 message 属性，可帮助开发定位问题
            }

        }
    }


}
